@extends('layouts.app')
@section('title')@parent-选择小区 @endsection
@section('content')
    <div class="container">
        <div class="row">
            <div class="col-lg-9 col-md-9 topic-list">
                <div class="card">
                    <div class="card-header bg-white">
                        <form class="form-inline select-city" method="get">
                            <label for="email">选择地区：</label>
                            <select class="form-control" name="province" id="province" onchange="selectProvince()">
                                <option value="">省份</option>
                                @foreach(\App\Models\District::where('parentid',0)->get() as $v)
                                    <option value="{{$v->id}}" {{isset($province_id) && $province_id == $v->id ? 'selected':''}}>{{$v->name}}</option>
                                @endforeach
                            </select>

                            <select class="form-control" name="city" style="margin-left: 10px" id="city" onchange="selectCity()">
                                <option value="">城市</option>
                                @if(isset($cities) && $cities->count() > 0)
                                    @foreach($cities as $v)
                                        <option value="{{$v->id}}" {{isset($city_id) && $city_id == $v->id ? 'selected':''}}>{{$v->name}}</option>
                                    @endforeach
                                @endif
                            </select>
                            @if(isset($counties) && $counties->count() > 0)
                            <select class="form-control" name="county" style="margin-left: 10px" id="county" onchange="selectCounty()">
                                <option value="">区/县</option>
                                @foreach($counties as $v)
                                    <option value="{{$v->id}}" {{isset($county_id) && $county_id == $v->id ? 'selected':''}}>{{$v->name}}</option>
                                @endforeach
                            </select>
                            @endif
                            &nbsp;
                            <input type="text" class="form-control" id="name" name="name" value="{{$name ?? ''}}" placeholder="关键字搜索社区">
                            <button type="submit" class="btn btn-primary">搜索</button>
                        </form>
                        <hr>
                        没有我关注的社区？加站长QQ：2462450809
                    </div>

                        <div class="card-body">

                            <ul class="media-list links">
                                <li class="media">
                                    <div class="media-body" style="margin-left: 0px">
                                        <div class="media-heading">
                                            <a class="font-weight-bold" href="{{route('communities.all')}}">
                                                查看全部
                                            </a>
                                        </div>
                                    </div>
                                </li>
                                <hr>
                                @if(isset($info) && $info->count() > 0)
                                    @foreach($info as $v)
                                        <li class="media">
                                            <div class="media-body" style="margin-left: 0px">
                                                <div class="media-heading">
                                                    <a class="font-weight-bold" href="{{route('communities.select',[$v->id])}}">
                                                        {{$v->name ?? ''}}
                                                    </a>
                                                </div>
                                                <div class="media-body meta" style="margin-top: 5px;">
                                                    <a class="font-weight-light" href="javascript:;">
                                                        {{$v->city->name ?? '无'}}
                                                    </a>
                                                    @if(isset($v->county->name))
                                                        <span> • </span>
                                                        <a class="font-weight-light" href="javascript:;">
                                                            {{$v->county->name}}
                                                        </a>
                                                    @endif
                                                </div>
                                            </div>
                                        </li>
                                        <hr>
                                    @endforeach
                                @endif
                            </ul>
                            {{$info->appends($_GET)->links()}}
                        </div>

                </div>
            </div>
        </div>

    </div>
@endsection
@section('scripts')
    <script>
        function selectProvince(){
            $('#city').val('');
            $('#county').val('');
            $('.select-city').submit();
        }
        function selectCity() {
            $('#county').val('');
            $('.select-city').submit();
        }
        function selectCounty(){
            $('.select-city').submit();
        }
    </script>
@endsection
